package com.xja.tt.controller;

import com.github.pagehelper.PageInfo;
import com.xja.tt.bean.Result;
import com.xja.tt.bean.Search;
import com.xja.tt.bean.User;
import com.xja.tt.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;

/**
 * @auther asus
 * @date 2021/12/22
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/findAllUser")
    @ResponseBody
    public Result findAllUser(@RequestBody Search search){
        System.out.println("Search=   "+search);
        try {
            PageInfo<User> pageInfo = userService.findAllUser(search);
            HashMap<String, Object> hashMap = new HashMap<>();
            hashMap.put("stuList",pageInfo.getList());
            hashMap.put("pageNum",pageInfo.getPageNum());
            hashMap.put("total",pageInfo.getTotal());
            Result result = Result.getResult(true, 200, "展示所有成功", hashMap);
            System.out.println("结果  "+result);
            return result;
        }catch (Exception e){
            System.out.println("查询出现异常"+e);
        }
        return Result.getResult(false, 444, "展示所有失败", null);
    }
}
